package com.lagou.controller;

import com.lagou.bean.OssResult;
import com.lagou.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/oss")
public class OssController {
    @Autowired
    private OssService ossService;

    @PostMapping("/upload")
    @ResponseBody
    public OssResult upload(@RequestParam("file") MultipartFile multipartFile) {
        return ossService.upload(multipartFile);
    }


    @GetMapping("/download")
    public void download(@RequestParam("name") String name, HttpServletResponse response) {
        ossService.download(name,response);
    }

    @GetMapping("/delete")
    @ResponseBody
    public OssResult delete(@RequestParam("name") String name) {
        return ossService.delete(name);
    }
}
